<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/10/16/016
 * Time: 17:44
 */

namespace app\common\model;


use think\Model;

class MemberConfig extends Model
{

    protected $append = [
        'type_text',
        'end_time_text',
        'end_time_num',
    ];


    public function getTypeTextAttr($value,$data)
    {
        $status = [1=>'小时',2=>'天',3=>'月'];
        return $status[$data['type']];
    }

    public function getEndTimeNumAttr($value,$data)
    {
        switch ($data['type']){
            case 1:
                $time = 60*60;
                break;
            case 2:
                $time = 60*60*24;
                break;
            case 3:
                $time = 60*60*24*31;
                break;
        }

        return $time * $data['end_time'];
    }



    public function getEndTimeTextAttr($value,$data)
    {
        $time = $this->getEndTimeNumAttr('',$data);
        return  \Carbon\Carbon::createFromTimestamp($time+time())->diffInDays() .'天VIP';
    }
    
    
    public function getList($map = []){
        return $this->alias('b')
            ->where($map)
            ->order('sort')
            ->paginate('',false,['query'=>request()->param()]);
    }
}